
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: {
    // 入口文件
    index: './src/index.js'
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name]-[hash:5].js',
  },
  devServer: {
    port: 8000,// http服务端口号
    hot: true, // 开启热更新
    overlay: { // 错误遮罩提示
      warnings: true,
      errors: true
    }
  },
  plugins: [
    new HtmlWebpackPlugin(
      { template: './public/index.html' }
    ),
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, 'static'), //定义要拷贝的源目录
          to: path.resolve(__dirname, 'dist', 'asset'), //定义要拷贝到的目标目录
        }
      ]
    })
  ]
}